﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GridTilesets
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private int[] _passages=new int[512];
        public MainWindow()
        {
            InitializeComponent();
            this.SetRowAndColumn();
            this.AddCheckBox();
        }

        private void SetRowAndColumn()
        {
            for (int i = 0; i < 8; i++)
            {
                grid2.ColumnDefinitions.Add(new ColumnDefinition(){Width =new GridLength(32)});
               // grid2.ColumnDefinitions.Add(new ColumnDefinition(){Width =GridLength.Auto});
            }

            for (int i = 0; i < 64; i++)
            {
                grid2.RowDefinitions.Add(new RowDefinition(){Height =new GridLength(32)});
               // grid2.RowDefinitions.Add(new RowDefinition(){Height = GridLength.Auto});
            }
            Grid.SetRowSpan(mytxt,64);
            Grid.SetColumnSpan(mytxt,8);
        }

        private void AddCheckBox()
        {
            int j = 0;
            for (int i = 0; i < _passages.Length; i++)
            {
                int r = i / 8;
                int c = i % 8;
                CheckBox checkBox = new CheckBox();
                checkBox.Checked += this.CheckBox_Checked;
                checkBox.Unchecked += this.CheckBox_Checked;
                checkBox.Width = 32;
                checkBox.Height =32;
                checkBox.IsChecked =  false;
                checkBox.Tag = new int[] { r, c }; 
                grid2.Children.Add(checkBox);
                Grid.SetRow(checkBox,r);
                Grid.SetColumn(checkBox,c);
                
            }
            
          
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox check = (CheckBox)sender;
            int[] tag = (int[])check.Tag;
            _passages[tag[0] * 8 + tag[1]] = check.IsChecked == true ? 1 : 0;
          
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string temp = string.Join(",", _passages);
            Console.WriteLine(temp);
        }
    }
}
